import http, {token} from './http';
import {
	GET_USER_CART_LIST_URL, 
	GET_USER_CART_COUNT_URL,
	ADD_USER_CART_LIST_URL,
	UPDATE_USER_CART_LIST_URL,
	DELETE_USER_CART_LIST_URL
} from './url.js'

// 请求用户购物车商品列表
const getUserCartList = (storeNo) => {
	return http({
		method: 'post',
		url: GET_USER_CART_LIST_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"isShowLoading": true,
			"userToken": token,
			"data": {
				"userId": 3644328,
				"storeNo": storeNo
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getUserCartList-err---', err)
	})
}

// 获取用户购物车商品数量
const getUserCartCount = () => {
	return http({
		method: 'post',
		url: GET_USER_CART_COUNT_URL,
		data: {
			"appId": 1005,
			"apiVersion": "5.0",
			"userToken": token,
			"data": {
				"userId": 3644328,
				"storeNo": "120"
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getUserCartCount-err---', err)
	})
}

// 获取用户购物车商品列表
const addUserCartList = (pId, store, quantity) => {
	return http({
		method: 'post',
		url: ADD_USER_CART_LIST_URL,
		data: {
			"appId": 1005,
			"apiVersion": "5.0",
			"isShowLoading": true,
			"userToken": token,
			"data": {
				"storeNo": store ? store : "133",
				"productClusterId": pId,
				"clientId": 1005,
				"quantity": quantity ? quantity : 1
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('addUserCartList-err---', err)
	})
}

// 更新用户购物车商品
const updateUserCartList = () => {
	return http({
		method: 'post',
		url: UPDATE_USER_CART_LIST_URL,
		data: {
			"appId": 1005,
			"apiVersion": "5.0",
			"isShowLoading": true,
			"userToken": token,
			"data": {
				"userId": 3644328,
				"storeNo": "133",
				"cartItemId": 5692811,
				"quantity": 2
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('updateUserCartList-err---', err)
	})
}

// 删除用户购物车商品
const deleteUserCartList = () => {
	return http({
		method: 'post',
		url: DELETE_USER_CART_LIST_URL,
		data: {
			"appId": 1005,
			"apiVersion": "5.0",
			"isShowLoading": true,
			"userToken": token,
			"data": {
				"userId": 3644328,
				"storeNo": "133",
				"cartItemIds": [6436089]
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('deleteUserCartList-err---', err)
	})
}

export {getUserCartList, getUserCartCount, addUserCartList, updateUserCartList, deleteUserCartList}